<?php
namespace TpAmis\Plugin\TableTextPopOver;

use TpAmis\Renderers\BaseRenderer;
use TpAmis\Renderers\Container;
use TpAmis\Renderers\Custom;
use TpAmis\Renderers\Tpl;

/**
 * 表格中设置长文本展示
 * Summary of TableTextPopOver
 */
class TableTextPopOver extends Container
{
    protected $style = ["max-width" => '100px'];
    protected $name = '';
    public function maxWidth(string $width = '100px')
    {
        $this->style["max-width"] = $width;

        return $this;
    }

    /**
     * 获取过滤后的结果
     * @return array
     */
    public function filteredResults(): array
    {

        $Tpl = Tpl::make();
        if (isset($this->amisSchema['name'])) {
            $Tpl->name($this->amisSchema['name']);
        }
        if (isset($this->amisSchema['label'])) {
            $Tpl->label($this->amisSchema['label']);
        }
        $Tpl = $Tpl->className("text-ellipsis")->style($this->style);

        if (isset($this->amisSchema['name'])) {
            $this->name = $this->amisSchema['name'];
        }
        $this->style(['display' => 'inline-block'])->body($Tpl)
            ->popOver(["body" => ["type" => "tpl", "tpl" => '${'.$this->name.'}']]);
        return $this->amisSchema;
    }
}
